package com.link.play.fit.ai.ui.adjust.adjustPage

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.link.play.fit.ai.bean.AdjustGoalsData
import com.link.play.fit.ai.bean.UserGuide
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.update

class AdjustPageModel : ViewModel() {
    var tempGoalsData: MutableStateFlow<AdjustGoalsData> = MutableStateFlow(AdjustGoalsData())
    var recentlyGoalData: MutableStateFlow<UserGuide> = MutableStateFlow(UserGuide())

    val fragmentValue = MutableLiveData<Boolean>(false)

    private val _goalLiveData = MutableLiveData<Int>()
    val goalLiveData: LiveData<Int> = _goalLiveData

    fun updateGoal(bean: Int) {
        _goalLiveData.postValue(bean)
    }

    fun getGoal(): Int {
        return _goalLiveData.value?:0
    }

    fun updateData(bean: UserGuide) {
        recentlyGoalData.update { bean }
    }

    fun getGoalData(): UserGuide {
        return recentlyGoalData.value
    }

    fun setGoalsValue(
        weekHabit: Int? = null,
        heigh: Int? = null,
        weightKg: Int? = null,
        goal: Int? = null,
        goalFast: Float? = null,
        ft: Int? = null,
        inches: Int? = null,
        isCm: Boolean? = null,
        lbs: Int? = null,
        goalWeightLbs: Int? = null,
        goalWeightKg:Int?=null,
        perWeightKg: Float? = null,

    ) {
        weekHabit?.let { k ->
            recentlyGoalData.update { it.copy(workouts = k) }
        }
        heigh?.let { k ->
            recentlyGoalData.update { it.copy(heightCm = k) }

        }
        weightKg?.let { k ->
//            recentlyGoalData.update { it.copy(weightkg = k) }
            recentlyGoalData.update { it.copy(weightKg = k) }

        }
        goal?.let { k ->
            recentlyGoalData.update { it.copy(goal = k) }
        }
        goalFast?.let { k ->
            recentlyGoalData.update { it.copy(perWeightLbsC = k) }
        }

        ft?.let { k ->
            recentlyGoalData.update { it.copy(heightFt = k) }
        }
        inches?.let { k ->
            recentlyGoalData.update { it.copy(heightIn = k) }
        }
        isCm?.let { k ->
            recentlyGoalData.update { it.copy(imperialMetric = k) }
        }
        lbs?.let { k ->
            recentlyGoalData.update { it.copy(weightLbs = k) }
        }
        goalWeightLbs?.let { k ->
            recentlyGoalData.update { it.copy(goalWeightLbs = k) }
        }
        goalWeightKg?.let { k ->
            recentlyGoalData.update { it.copy(goalWeightKg = k) }
        }
        perWeightKg?.let { k ->
            recentlyGoalData.update { it.copy(perWeightKg = k) }
        }
    }

    fun setNextPage(isNext: Boolean) {
        fragmentValue.value = isNext
    }

}